Access Funktionen
In diesem Artikel befinden sich einige nützliche Funktionen rund um Access VBA. Teilweise wird Access um weitere Funktionen erweitert oder aber bestehende Funktionen werden durch flexiblere oder performantere ersetzt.
Public Function CDateSQL(vardatum As Variant) As String
If IsDate(vardatum) Then
CDateSQL = Format(CDate(vardatum), "'yyyy-mm-dd'")
End If
End Function
Public Function aDoLookupSQL(ByVal sSQL As String, Optional conAlternativ As ADODB.Connection = Null) As Variant
Dim rst As ADODB.Recordset
Dim con As ADODB.Connection
If conAlternativ Is Nothing Then
Set con = CurrentProject.Connection
Else
Set con = conAlternativ
End If
On Error GoTo HandleErr
Set rst = New ADODB.Recordset
With rst
.Open sSQL, con, adOpenForwardOnly, adLockReadOnly
If .BOF Then
aDoLookupSQL = Null
Else
aDoLookupSQL = .Fields(0)
End If
.Close
End With
ExitHere:
Set rst = Nothing
Exit Function
HandleErr:
aDoLookupSQL = Null
Resume ExitHere
End Function
Public Function aDoLookup(feld As String, tabelle As String, where As String) As Variant
Dim strSQL As String
strSQL = "SELECT " & feld & " FROM " & tabelle & " WHERE " & where
aDoLookup = aDoLookupSQL(strSQL)
End Function